import { Controller, Get, Post, Body, Patch, Param, Delete, UseFilters} from '@nestjs/common';
import { FoodsService } from './foods.service';
import { CreateFoodDto } from './dto/create-food.dto';
import { UpdateFoodDto } from './dto/update-food.dto';
import { HttpExceptionFilter } from 'src/exception/http-exception.filter';

@Controller('foods')
export class FoodsController {
  constructor(private readonly foodsService: FoodsService) {}

  @Post()
  create(@Body() createFoodDto: CreateFoodDto) {
    console.log(createFoodDto)
    return this.foodsService.create(createFoodDto);
  }

  @Get()
  findAll() {
    return this.foodsService.findAll();
  }

  @Get('/data/:id')
  @UseFilters(new HttpExceptionFilter())
  findOne(@Param() params: number) {
    return this.foodsService.findOne(params);
  }

  @Patch(':id')
  @UseFilters(new HttpExceptionFilter())
  update(@Param('id') id: string, @Body() updateFoodDto: UpdateFoodDto) {
    return this.foodsService.update(+id, updateFoodDto);
  }

  @Delete(':id')
  @UseFilters(new HttpExceptionFilter())
  remove(@Param('id') id: string) {
    return this.foodsService.remove(+id);
  }
}
